/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package poker.game;

/**
 * The class which represents cards. Note that class does not implement comparable
 * because this could cause problems is certain collections, i.e., equal in value
 * is not the same as .equals.
 *
 * 
 *
 * @author Benjamin L. Brodie <blbrodie@gmail.com>
 */
 public class Card implements Comparable<Card>{
    //the value is the value value. For ease of use, these are correspond to the
    //actual card value values and Ace = 14.
    private int value;

    //the suite, there are four
    private int suite;

    /**
     *
     * @param value the value value, where card 2 = 2, jack = 11, queen = 12,
     * king = 13, Ace = 14
     * @param suite the suite, there are four, correspondence with symbols is
     * not important
     */
    public Card(int value, int suite){
        if (value > 14 || value < 2){
            throw new IllegalArgumentException("Card face must be from 2 - 14");
        } else if(suite > 4){
            throw new IllegalArgumentException("Suite value must be from 1 - 4");
        }

        this.value = value;
        this.suite = suite;
    }

  
    /**
     *
     * @return the value value, where 2 =2 , jack = 11, queen = 12, king = 13,
     * Ace = 14
     */
    public int getValue(){
        return value;
    }

    /**
     *
     * @return the suite, symbol is not important
     */
    public int getSuite(){
        return suite;
    }

    /**
     * Note: Comparable is inconsistent with equals! Different suits will be
     * comparably equal, but not ==. Read Java API for sets
     * and on comparable, if this poses an issue. This is not an issue for
     * ArrayList.
     *
     *
     * @param c the card to be compared to
     * @return -1 if <, 0 if =, 1 if >
     */
    @Override
    public int compareTo(Card c) {

        if (value < c.value){
            return -1;
        }

        if (value > c.value){
            return 1;
        }

        else return 0;
    }


    /**
     *
     * @return e.g., "King of Diamonds" or "2 of Spades".
     */
    @Override
    public String toString(){
        String sValue = "";
        String sSuite = "";

        switch (suite){
            case (1): sSuite = "Clubs"; break;
            case (2): sSuite = "Diamonds"; break;
            case (3): sSuite = "Hearts"; break;
            case (4): sSuite = "Spades"; break;
            default: sSuite = "error";
        }


        if (value < 11) {
            sValue = value + " of ";
        } else {
            switch (value) {
                case (11):
                    sValue = "Jack of ";
                    break;
                case (12):
                    sValue = "Queen of ";
                    break;
                case (13):
                    sValue = "King of ";
                    break;
                case (14):
                    sValue = "Ace of ";
                    break;
                default:
                    sValue = "error";
            }
        }
        return sValue + sSuite;
    }

    public static void main(String[] args){
        Card a = new Card(3,3);
        Card b = new Card(4,4);
        Card c = new Card(2,2);
        Card d = new Card(3,1);

        System.out.println("Should print -1");
        System.out.println(a.compareTo(b));

        System.out.println("Should print 1");
        System.out.println(a.compareTo(c));

        System.out.println("Should print 0");
        System.out.println(a.compareTo(d));
    }
    
    


    
}
